//
//  OSLoginVC.m
//  ZKPayApp
//
//  Created by 凯朱 on 2024/10/30.
//

#import "OSLoginVC.h"
#import "OSSendCodeVC.h"
@interface OSLoginVC ()

@end

@implementation OSLoginVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = kColor_W;
    _sureBtn.layer.cornerRadius = 25;
    _sureBtn.layer.masksToBounds = YES;
    _bgView.layer.cornerRadius = 10;
    _bgView.layer.shadowColor = [UIColor colorWithRed:105/255.0 green:126/255.0 blue:196/255.0 alpha:0.16].CGColor;
    _bgView.layer.shadowOffset = CGSizeMake(0,6);
    _bgView.layer.shadowOpacity = 1;
    _bgView.layer.shadowRadius = 16;
    [self addTextLabel];
    _tf.placeholder = kLocalString(@"请输入您的手机号码");
    _lbl2.text = kLocalString(@"正规持牌金融机构");
//    _tf.text = @"8863453453";
       
}

/*
 添加富文本点击事件
 */
-(void)addTextLabel{
    
    NSString *textStr = kLocalString(@"登录即代表你同意《服务条款》和《隐私政策》");
    
    __block NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:textStr];
    text.color = kHexColor(@"#A4B4EB");
    
    NSRange range = [textStr rangeOfString:kLocalString(@"《服务条款》")];
    [text setTextHighlightRange:range color:kColor_T backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull clickText, NSRange range, CGRect rect) {
        LTBaseWebViewController *vc = [LTBaseWebViewController new];
        vc.homeURL = @"https://www.baidu.com";
        [self.navigationController pushViewController:vc animated:YES];
    }];
    
    NSRange range2 = [textStr rangeOfString:kLocalString(@"《隐私政策》")];
    [text setTextHighlightRange:range2 color:kColor_T backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull clickText, NSRange range, CGRect rect) {
        LTBaseWebViewController *vc = [LTBaseWebViewController new];
        vc.homeURL = @"https://www.baidu.com";
        [self.navigationController pushViewController:vc animated:YES];
    }];
    
    YYLabel *textLabel = [YYLabel new];
    text.font = kFont(12);
    text.lineSpacing = 6;
    textLabel.numberOfLines = 0;
    textLabel.attributedText = text;
    textLabel.textAlignment = NSTextAlignmentCenter;
    //设置换行方式
    NSMutableParagraphStyle  *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
    paragraphStyle.lineSpacing = 6;
    text.paragraphStyle = paragraphStyle;
    text.alignment = NSTextAlignmentCenter;
    
    //计算文本尺寸
    CGSize maxSize = CGSizeMake(KScreenWidth-40, MAXFLOAT);
    YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:maxSize text:text];
    textLabel.textLayout = layout;
    CGFloat introHeight = layout.textBoundingSize.height;
    textLabel.left = 0;
    textLabel.width = maxSize.width;
    textLabel.height = introHeight;
    [_bottomView addSubview:textLabel];
}


- (IBAction)sureAction:(id)sender {
    if (_tf.text.length == 0) {
        kShowToast(@"输入手机号码");
        return;
    }
    NSDictionary *params = @{@"phone":_tf.text};
    [OSTool showHudOnWindow];
    [OSHttpManager postWithPath:@"login/captcha" params:params finished:^(BOOL isSuccessed, id result, NSString *code, NSString *message) {
        [OSTool hideHudOnKeyWindow];
        if (!isSuccessed) {
            kShowToast(message);
            return;
        }
        OSSendCodeVC *vc = [[OSSendCodeVC alloc] init];
        vc.tel = self->_tf.text;
        [self.navigationController pushViewController:vc animated:YES];
    }];
}

@end
